<?php
// +----------------------------------------------------------------------
// | CoreThink [ Simple Efficient Excellent ]
// +----------------------------------------------------------------------
// | Copyright (c) 2014 http://www.corethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: jry <598821125@qq.com> <http://www.corethink.cn>
// +----------------------------------------------------------------------
namespace Admin\Controller;
use Think\Controller;
/**
 * 后台用户控制器
 * @author jry <598821125@qq.com>
 */
class UserController extends AdminController{
    /**
     * 用户列表
     * @author jry <598821125@qq.com>
     */
    public function index(){
        //搜索
        $keyword = I('keyword', '', 'string');
        $condition = array('like','%'.$keyword.'%');
        $map['id|username|email|mobile'] = array($condition, $condition, $condition, $condition,'_multi'=>true);
        $map['status'] = array('egt', '0'); //禁用和正常状态
        $data_list = D('User')->where($map)->order('sort asc, id asc')->select();


        $x = $_GET['select'];
        switch ($x)
        {
            case 1:
                $map['status'] = array('egt', '0'); //禁用和正常状态
                $data_list = D('User')->page(!empty($_GET["p"])?$_GET["p"]:1, C('ADMIN_PAGE_ROWS'))->where($map)->order('sort desc,id desc')->select();
                $page = new \Common\Util\Page(D('User')->where($map)->count(), C('ADMIN_PAGE_ROWS'));
                $ab=D('user')->where($map)->select();
                $user_total=count($ab);
                $listName = '全部会员';
                break;
            case 2:
                $map['jh_yq_ma'] = array('eq', 1); //禁用和正常状态
                $map['status'] = array('neq', 0);
                $data_list = D('User')->page(!empty($_GET["p"])?$_GET["p"]:1, C('ADMIN_PAGE_ROWS'))->where($map)->order('sort desc,id desc')->select();
                $page = new \Common\Util\Page(D('User')->where($map)->count(), C('ADMIN_PAGE_ROWS'));
                $ab=D('user')->where($map)->select();
                $user_total=count($ab);
                $listName = '已激活会员';
                break;
            case 3:
                $map['jh_yq_ma'] = array('eq', 0); //禁用和正常状态
                $map['status'] = array('neq', 0);
                $data_list = D('User')->page(!empty($_GET["p"])?$_GET["p"]:1, C('ADMIN_PAGE_ROWS'))->where($map)->order('sort desc,id desc')->select();
                $page = new \Common\Util\Page(D('User')->where($map)->count(), C('ADMIN_PAGE_ROWS'));
                $ab=D('user')->where($map)->select();
                $user_total=count($ab);
                $listName = '未激活会员';
                break;
            case 4:
                $map['lbw_viplevel'] = array('eq', 0); //禁用和正常状态
                $map['status'] = array('neq', 0);
                $data_list = D('User')->page(!empty($_GET["p"])?$_GET["p"]:1, C('ADMIN_PAGE_ROWS'))->where($map)->order('sort desc,id desc')->select();
                $page = new \Common\Util\Page(D('User')->where($map)->count(), C('ADMIN_PAGE_ROWS'));
                $ab=D('user')->where($map)->select();
                $user_total=count($ab);
                $listName = 'v1会员';
                break;
            case 5:
                $map['lbw_viplevel'] = array('eq', 1); //禁用和正常状态
                $map['status'] = array('neq', 0);
                $data_list = D('User')->page(!empty($_GET["p"])?$_GET["p"]:1, C('ADMIN_PAGE_ROWS'))->where($map)->order('sort desc,id desc')->select();
                $page = new \Common\Util\Page(D('User')->where($map)->count(), C('ADMIN_PAGE_ROWS'));
                $ab=D('user')->where($map)->select();
                $user_total=count($ab);
                $listName = 'v2会员';
                break;
            case 6:
                $map['lbw_viplevel'] = array('eq', 2); //禁用和正常状态
                $map['status'] = array('neq', 0);
                $data_list = D('User')->page(!empty($_GET["p"])?$_GET["p"]:1, C('ADMIN_PAGE_ROWS'))->where($map)->order('sort desc,id desc')->select();
                $page = new \Common\Util\Page(D('User')->where($map)->count(), C('ADMIN_PAGE_ROWS'));
                $ab=D('user')->where($map)->select();
                $user_total=count($ab);
                $listName = 'v3会员';
                break;
            case 7:
                $map['lbw_viplevel'] = array('eq', 3); //禁用和正常状态
                $map['status'] = array('neq', 0);
                $data_list = D('User')->page(!empty($_GET["p"])?$_GET["p"]:1, C('ADMIN_PAGE_ROWS'))->where($map)->order('sort desc,id desc')->select();
                $page = new \Common\Util\Page(D('User')->where($map)->count(), C('ADMIN_PAGE_ROWS'));
                $ab=D('user')->where($map)->select();
                $user_total=count($ab);
                $listName = 'v4会员';
                break;
            case 8:
                $map['status'] = array('eq', 0); //禁用和正常状态
                $data_list = D('User')->page(!empty($_GET["p"])?$_GET["p"]:1, C('ADMIN_PAGE_ROWS'))->where($map)->order('sort desc,id desc')->select();
                $page = new \Common\Util\Page(D('User')->where($map)->count(), C('ADMIN_PAGE_ROWS'));
                $ab=D('user')->where($map)->select();
                $user_total=count($ab);
                $listName = '冻结会员';
                break;
            default:
                $map['status'] = array('egt', '0'); //禁用和正常状态
                $data_list = D('User')->page(!empty($_GET["p"])?$_GET["p"]:1, C('ADMIN_PAGE_ROWS'))->where($map)->order('sort desc,id desc')->select();
                $page = new \Common\Util\Page(D('User')->where($map)->count(), C('ADMIN_PAGE_ROWS'));
                $ab=D('user')->where($map)->select();
                $user_total=count($ab);
                $listName = '全部会员';
                break;
        }

        //获取所有用户
        $builder = new \Common\Builder\ListBuilder();
        $builder->setMetaTitle('用户管理');
        $this->assign('page',$page->show());
        $this->assign('data_list',$data_list);
        $this->assign('listname',$listName);
        $this->assign('keykey','ilikemilke');
        $this->assign('total',$user_total);
        $this->display();
    }
//信息修改
     public function bianJi(){
        $data['username']=trim(I('post.username'));
         $date['username']=trim(I('post.username')); //构造用户名找寻会员条件
         $data['password'] =trim(I('post.password','', 'user_md5'));
         $data['lbw_twopwd'] =trim(I('post.lbw_twopwd','','user_md5'));
         $data['mobile'] =trim(I('post.mobile'));
         $data['idcard_no'] =trim(I('post.idcard_no'));
         $data['bank_number'] =trim(I('post.bank_number'));
         $data['realname']  =trim(I('post.realname'));
          $a=trim(I('post.lbw_viplevel'));  //检测等级提升多少
         $data_cx['username']=trim(I('post.username'));
         //获取系统参数设置
         $datacig_v2['name'] = "LBW_VTWO_USER"; //获取v2设置
         $lbw_config_v2 = D('SystemConfig')->where($datacig_v2)->getField('value');//获取v2设置
         $datacig_v3['name'] = "LBW_VTHREE_USER"; //获取v3设置
         $lbw_config_v3 = D('SystemConfig')->where($datacig_v3)->getField('value');//获取v3设置
         $datacig_v4['name'] = "LBW_VFOUR_USER"; //获取v4设置
         $lbw_config_v4 = D('SystemConfig')->where($datacig_v4)->getField('value');//获取v4设置
         if($a == 1){
            $b=D('User')->where($data_cx)->getField('lbw_zhitui');  //增加相应的直推人数
             $c=$b+$lbw_config_v2;
         }elseif($a==2){
             $b=D('User')->where($data_cx)->getField('lbw_zhitui'); //增加相应的直推人数
             $c=$b+$lbw_config_v3;
         }elseif($a==3){
             $b=D('User')->where($data_cx)->getField('lbw_zhitui'); //增加相应的直推人数
             $c=$b+$lbw_config_v4*20;
         }else{
             $b=D('User')->where($data_cx)->getField('lbw_zhitui'); //增加相应的直推人数
             $c=$b+0;
         }
         $data['lbw_viplevel']=trim(I('post.lbw_viplevel'));
         $data['lbw_zhitui']=$c;//增加相应的直推人数
         D('User')->where($date)->save($data);
         $this->success('信息修改成功');
     }
    //冻结账号
    public function dongJie(){
        $userid=$_GET['id'];
        $data['id']=$userid;
        $date['status']=0;
        D('User')->where($data)->save($date);
        $this->success('冻结成功');
    }
    //解冻账号
    public function yjjiedong(){
        $userid=$_GET['id'];
        $data['id']=$userid;
        $date['status']=1;
        D('User')->where($data)->save($date);
        $this->success('解冻成功');
    }
    //锁定提现
    public function suoDing(){
        $user_id=$_GET['id'];
        $data['id']=$user_id;
        $date['tixian_sd']=1;
        D('User')->where($data)->save($date);
        $this->success('锁定成功');
    }
    //解锁提现
    public function yjjiesuo(){
        $user_id=$_GET['id'];
        $data['id']=$user_id;
        $date['tixian_sd']=0;
        D('User')->where($data)->save($date);
        $this->success('解锁成功');
    }

    /**
     * 新增用户
     * @author jry <598821125@qq.com>
     */
    public function add(){
        if(IS_POST){
            $user_object = D('User');
            $data = $user_object->create();
            if($data){
                $id = $user_object->add();
                if($id){
                    $this->success('新增成功', U('index'));
                }else{
                    $this->error('新增失败');
                }
            }else{
                $this->error($user_object->getError());
            }
        }else{
            $user_object = D('User');

            //使用FormBuilder快速建立表单页面。
            $builder = new \Common\Builder\FormBuilder();
            $builder->setMetaTitle('新增用户') //设置页面标题
                    ->setPostUrl(U('add')) //设置表单提交地址
                    ->addFormItem('reg_type', 'hidden', '注册方式', '注册方式')
                    ->addFormItem('usertype', 'radio', '用户类型', '用户类型', $user_object->user_type())
                    ->addFormItem('username', 'text', '用户名', '用户名')
                    ->addFormItem('email', 'text', '邮箱', '邮箱')
                    ->addFormItem('mobile', 'text', '手机号码', '手机号码')
                    ->addFormItem('password', 'password', '密码', '密码')
                    ->addFormItem('avatar', 'picture', '用户头像', '用户头像')
                    ->addFormItem('vip', 'radio', 'VIP等级', 'VIP等级', $user_object->user_vip_level())
                    ->setFormData(array('reg_type' => 1)) //注册方式为后台添加
                    ->display();
        }
    }

    /**
     * 编辑用户
     * @author jry <598821125@qq.com>
     */
    public function edit($id){
        //获取用户信息
        $info = D('User')->find($id);

        if(IS_POST){
            $user_object = D('User');
            //不修改密码时销毁变量
            if($_POST['password'] == '' || $info['password'] == $_POST['password']){
                unset($_POST['password']);
            }else{
                $_POST['password'] = user_md5($_POST['password']);
            }
            //不允许更改超级管理员用户组
            if($_POST['id'] == 1){
                unset($_POST['group']);
            }
            if($_POST['extend']){
                $_POST['extend'] = json_encode($_POST['extend']);
            }
            if($user_object->save($_POST)){
                $this->success('更新成功', U('index'));
            }else{
                $this->error('更新失败', $user_object->getError());
            }
        }else{
            $user_object = D('User');
            $info = $user_object->find($id);
            //使用FormBuilder快速建立表单页面。
            $builder = new \Common\Builder\FormBuilder();
            $builder->setMetaTitle('编辑用户') //设置页面标题
                    ->setPostUrl(U('edit')) //设置表单提交地址
                    ->addFormItem('id', 'hidden', 'ID', 'ID')
                    ->addFormItem('usertype', 'radio', '用户类型', '用户类型', $user_object->user_type())
                    ->addFormItem('group', 'select', '部门', '所属部门', select_list_as_tree('UserGroup', null, '默认部门'))
                    ->addFormItem('username', 'text', '用户名', '用户名')
                    ->addFormItem('email', 'text', '邮箱', '邮箱')
                    ->addFormItem('mobile', 'text', '手机号码', '手机号码')
                    ->addFormItem('password', 'password', '密码', '密码')
                    ->addFormItem('avatar', 'picture', '用户头像', '用户头像')
                    ->addFormItem('vip', 'radio', 'VIP等级', 'VIP等级', $user_object->user_vip_level())
                    ->setFormData($info)
                    ->display();
        }
    }
    /*
     * 打款明细列表
     */
    public function dkList(){
        $x = $_GET['select'];
        if($x==7 or $x == 8){
        //获取所有用户
        $keyword = I('keyword', '', 'string');
        $condition = array('like','%'.$keyword.'%');
        $map['dk_odr_ordernumber|dk_lbw_order_pipei|dk_money_total'] = array($condition, $condition, $condition, '_multi'=>true);
        $data_list = D('UserPipeioder')->where($map)->order('sf_dd_crt_time asc')->select();
        }else{
            //获取所有用户
            $keyword = I('keyword', '', 'string');
            $condition = array('like','%'.$keyword.'%');
            $map['lbw_vipid|username|lbw_order_pipei|money_total'] = array($condition, $condition, $condition, $condition,'_multi'=>true);
            $data_list = D('UserTemppipeiorder')->where($map)->order('creattime asc')->select();
        }
        switch ($x)
        {
            case 1:
                $map['jiaoyi_zt'] = array('neq', '19'); //禁用和正常状态
                $data_list = D('UserTemppipeiorder')->page(!empty($_GET["p"])?$_GET["p"]:1, C('ADMIN_PAGE_ROWS'))->where($map)->order('sort desc,id desc')->select();
                $page = new \Common\Util\Page(D('UserTemppipeiorder')->where($map)->count(), C('ADMIN_PAGE_ROWS'));
                $ab=D('UserTemppipeiorder')->where($map)->select();
                $user_total=count($ab);

                for($i=0;$i<$user_total;$i++){
                    $money_total=$money_total+$ab[$i]['total_forever'];  //排单总金额
                    $money_ypp=$money_ypp+$ab[$i]['yipipei_money'];   //已匹配金额
                }
                $listName = '全部订单';
                $typenum=1;
                break;
            case 2:

                $map['peidui_cishu'] = array('eq', '0');
                $data_list = D('UserTemppipeiorder')->page(!empty($_GET["p"])?$_GET["p"]:1, C('ADMIN_PAGE_ROWS'))->where($map)->order('sort desc')->select();
                $page = new \Common\Util\Page(D('UserTemppipeiorder')->where($map)->count(), C('ADMIN_PAGE_ROWS'));
                $ab=D('UserTemppipeiorder')->where($map)->select();
                $user_total=count($ab);

                for($i=0;$i<$user_total;$i++){
                    $money_total=$money_total+$ab[$i]['total_forever'];  //排单总金额
                    $money_ypp=$money_ypp+$ab[$i]['yipipei_money'];   //已匹配金额
                }

                $listName = '等待配对';
                $typenum=1;
                break;
            case 3:
                $map['peidui_cishu'] = array('EGT', '1');
                $data_list = D('UserTemppipeiorder')->page(!empty($_GET["p"])?$_GET["p"]:1, C('ADMIN_PAGE_ROWS'))->where($map)->order('sort desc')->select();
                $page = new \Common\Util\Page(D('UserTemppipeiorder')->where($map)->count(), C('ADMIN_PAGE_ROWS'));
                $ab=D('UserTemppipeiorder')->where($map)->select();
                $user_total=count($ab);

                for($i=0;$i<$user_total;$i++){
                    $money_total=$money_total+$ab[$i]['total_forever'];  //排单总金额
                    $money_ypp=$money_ypp+$ab[$i]['yipipei_money'];   //已匹配金额
                }

                $listName = '已配对';
                $typenum=1;
                break;
            case 4:
                $map['jiaoyi_zt'] = array('eq', 9);
                $data_list = D('UserTemppipeiorder')->page(!empty($_GET["p"])?$_GET["p"]:1, C('ADMIN_PAGE_ROWS'))->where($map)->order('sort desc')->select();
                $page = new \Common\Util\Page(D('UserTemppipeiorder')->where($map)->count(), C('ADMIN_PAGE_ROWS'));
                $ab=D('UserTemppipeiorder')->where($map)->select();
                $user_total=count($ab);

                for($i=0;$i<$user_total;$i++){
                    $money_total=$money_total+$ab[$i]['total_forever'];  //排单总金额
                    $money_ypp=$money_ypp+$ab[$i]['yipipei_money'];   //已匹配金额
                }

                $listName = '超时关闭';
                $typenum=1;
                break;
            case 5:
                $map['peidui_cishu'] = array('EGT', '1');
                $data_list = D('UserTemppipeiorder')->page(!empty($_GET["p"])?$_GET["p"]:1, C('ADMIN_PAGE_ROWS'))->where($map)->order('sort desc')->select();
                $page = new \Common\Util\Page(D('UserTemppipeiorder')->where($map)->count(), C('ADMIN_PAGE_ROWS'));
                $ab=D('UserTemppipeiorder')->where($map)->select();
                $user_total=count($ab);

                for($i=0;$i<$user_total;$i++){
                    $money_total=$money_total+$ab[$i]['total_forever'];  //排单总金额
                    $money_ypp=$money_ypp+$ab[$i]['yipipei_money'];   //已匹配金额
                }

                $listName = '交易中';
                $typenum=1;
                break;
            case 6:
                $map['jiaoyi_zt'] = array('eq', '2');
                $data_list = D('UserTemppipeiorder')->page(!empty($_GET["p"])?$_GET["p"]:1, C('ADMIN_PAGE_ROWS'))->where($map)->order('sort desc')->select();
                $page = new \Common\Util\Page(D('UserTemppipeiorder')->where($map)->count(), C('ADMIN_PAGE_ROWS'));
                $ab=D('UserTemppipeiorder')->where($map)->select();
                $user_total=count($ab);

                for($i=0;$i<$user_total;$i++){
                    $money_total=$money_total+$ab[$i]['total_forever'];  //排单总金额
                    $money_ypp=$money_ypp+$ab[$i]['yipipei_money'];   //已匹配金额
                }

                $listName = '交易成功';
                $typenum=1;
                break;
            case 7:
                $map['dk_dakuan_status'] = array('neq', 0);
                $data_list = D('UserPipeioder')->page(!empty($_GET["p"])?$_GET["p"]:1, C('ADMIN_PAGE_ROWS'))->where($map)->order('sort desc')->select();
                $page = new \Common\Util\Page(D('UserPipeioder')->where($map)->count(), C('ADMIN_PAGE_ROWS'));
                $ab=D('UserPipeioder')->where($map)->select();
                $user_total=count($ab);

                for($i=0;$i<$user_total;$i++){
                    $money_total=$money_total+$ab[$i]['dk_money_total'];  //排单总金额
                }

                $listName = '已打款';
                $typenum=2;
                break;
            case 8:
                $map['sf_jy_status'] = array('eq', '8');
                $data_list = D('UserPipeioder')->page(!empty($_GET["p"])?$_GET["p"]:1, C('ADMIN_PAGE_ROWS'))->where($map)->order('sort desc')->select();
                $page = new \Common\Util\Page(D('UserPipeioder')->where($map)->count(), C('ADMIN_PAGE_ROWS'));
                $ab=D('UserPipeioder')->where($map)->select();
                $user_total=count($ab);

                for($i=0;$i<$user_total;$i++){
                    $money_total=$money_total+$ab[$i]['dk_money_total'];  //排单总金额
                }

                $listName = '待抢单';
                $typenum=2;
                break;
            case 9:
                $timetoday = date("Y-m-d",time());
                $time2 = $timetoday + 3600*24;

                $map['sf_dd_crt_time'] = array('between',array('1','8'));
                $data_list = D('UserTemppipeiorder')->page(!empty($_GET["p"])?$_GET["p"]:1, C('ADMIN_PAGE_ROWS'))->where($map)->order('sort desc')->select();
                $page = new \Common\Util\Page(D('UserTemppipeiorder')->where($map)->count(), C('ADMIN_PAGE_ROWS'));
                $ab=D('UserTemppipeiorder')->where($map)->select();
                $user_total=count($ab);

                for($i=0;$i<$user_total;$i++){
                    $money_total=$money_total+$ab[$i]['total_forever'];  //排单总金额
                    $money_ypp=$money_ypp+$ab[$i]['yipipei_money'];   //已匹配金额
                }

                $listName = '交易成功';
                $typenum=1;
                break;
            case 10:
                $map['creattimetwo']=array('LT',time());
                $map['peidui_cishu']=array('eq',0);
                $data_list = D('UserTemppipeiorder')->page(!empty($_GET["p"])?$_GET["p"]:1, C('ADMIN_PAGE_ROWS'))->where($map)->order('sort desc')->select();
                $page = new \Common\Util\Page(D('UserTemppipeiorder')->where($map)->count(), C('ADMIN_PAGE_ROWS'));
                $ab=D('UserTemppipeiorder')->where($map)->select();
                $user_total=count($ab);

                for($i=0;$i<$user_total;$i++){
                    $money_total=$money_total+$ab[$i]['total_forever'];  //排单总金额
                    $money_ypp=$money_ypp+$ab[$i]['yipipei_money'];   //已匹配金额
                }

                $listName = '可以匹配';
                $typenum=1;
                break;
            case 11:
                $map['ketixian_zt'] = array('eq',1);
                $data_list = D('UserTemppipeiorder')->page(!empty($_GET["p"])?$_GET["p"]:1, C('ADMIN_PAGE_ROWS'))->where($map)->order('sort desc')->select();
                $page = new \Common\Util\Page(D('UserTemppipeiorder')->where($map)->count(), C('ADMIN_PAGE_ROWS'));
                $ab=D('UserTemppipeiorder')->where($map)->select();
                $user_total=count($ab);

                for($i=0;$i<$user_total;$i++){
                    $money_total=$money_total+$ab[$i]['total_forever'];  //排单总金额
                    $money_ypp=$money_ypp+$ab[$i]['yipipei_money'];   //已匹配金额
                }

                $listName = '冻结中';
                $typenum=1;
                break;
            default:
                $map['jiaoyi_zt'] = array('neq', '19'); //禁用和正常状态
                $data_list = D('UserTemppipeiorder')->page(!empty($_GET["p"])?$_GET["p"]:1, C('ADMIN_PAGE_ROWS'))->where($map)->order('sort desc')->select();
                $page = new \Common\Util\Page(D('UserTemppipeiorder')->where($map)->count(), C('ADMIN_PAGE_ROWS'));
                $ab=D('UserTemppipeiorder')->where($map)->select();
                $user_total=count($ab);

                for($i=0;$i<$user_total;$i++){
                    $money_total=$money_total+$ab[$i]['total_forever'];  //排单总金额
                    $money_ypp=$money_ypp+$ab[$i]['yipipei_money'];   //已匹配金额
                }

                $listName = '全部订单';
                $typenum=1;
                break;
        }


        //获取所有用户
        $builder = new \Common\Builder\ListBuilder();
        $builder->setMetaTitle('打款排队列表'); //设置页面标题
        $this->assign('page',$page->show());
        $this->assign('data_list',$data_list);
        $this->assign('listname',$listName);
        $this->assign('moneytotal',$money_total);
        $this->assign('moneyypp',$money_ypp);
        $this->assign('keykey','ilikemilke');
        $this->assign('total',$user_total);
        $this->assign('typenum',$typenum);
        $this->display();

    }
    /*
     * 打款明细列表二
     */
    public function dklisttwo(){
        $dh=$_GET['dh'];
        $type=$_GET['type'];
        if($type==1){  //等于1是原始订单

            $map['dk_odr_ordernumber'] = $dh;
            $data_list = D('UserPipeioder')->page(!empty($_GET["p"])?$_GET["p"]:1, C('ADMIN_PAGE_ROWS'))->where($map)->order('sort desc')->select();
            $page = new \Common\Util\Page(D('UserPipeioder')->where($map)->count(), C('ADMIN_PAGE_ROWS'));
            $ab=D('UserPipeioder')->where($map)->select();
            $user_total=count($ab);

            for($i=0;$i<$user_total;$i++){
                $money_total=$money_total+$ab[$i]['dk_money_total'];  //排单总金额
            }

            $listName = '匹配详情';

        }else{      //等于2进到双方交易状态


        }
        $builder = new \Common\Builder\ListBuilder();
        $builder->setMetaTitle('打款排队列表'); //设置页面标题
        $this->assign('page',$page->show());
        $this->assign('data_list',$data_list);
        $this->assign('listname',$listName);
        $this->assign('moneytotal',$money_total);
        $this->assign('keykey','ilikemilke');
        $this->assign('total',$user_total);
        $this->display();

    }

    public function skList(){
        $x = $_GET['select'];
        if($x==7 or $x == 8){
            //获取所有用户
            $keyword = I('keyword', '', 'string');
            $condition = array('like','%'.$keyword.'%');
            $map['dk_odr_ordernumber|dk_lbw_order_pipei|dk_money_total'] = array($condition, $condition, $condition, '_multi'=>true);
            $data_list = D('UserPipeioder')->where($map)->order('sf_dd_crt_time asc')->select();
        }else{
            //获取所有用户
            $keyword = I('keyword', '', 'string');
            $condition = array('like','%'.$keyword.'%');
            $map['lbw_vipid|username|lbw_order_sk_id|money_total'] = array($condition, $condition, $condition, $condition,'_multi'=>true);
            $data_list = D('UserTempskorder')->where($map)->order('creattime asc')->select();
        }
        switch ($x)
        {
            case 1:
                $map['jiaoyi_zt'] = array('neq', '19'); //禁用和正常状态
                $data_list = D('UserTempskorder')->page(!empty($_GET["p"])?$_GET["p"]:1, C('ADMIN_PAGE_ROWS'))->where($map)->order('sort desc,id desc')->select();
                $page = new \Common\Util\Page(D('UserTempskorder')->where($map)->count(), C('ADMIN_PAGE_ROWS'));
                $ab=D('UserTempskorder')->where($map)->select();
                $user_total=count($ab);

                for($i=0;$i<$user_total;$i++){
                    $money_total=$money_total+$ab[$i]['total_sk'];  //排单总金额
                    $money_ypp=$money_ypp+$ab[$i]['yipipei_money'];   //已匹配金额
                }
                $listName = '全部订单';
                $typenum=1;
                break;
            case 2:

                $map['shoukuan_cishu'] = array('eq', '0');
                $data_list = D('UserTempskorder')->page(!empty($_GET["p"])?$_GET["p"]:1, C('ADMIN_PAGE_ROWS'))->where($map)->order('sort desc')->select();
                $page = new \Common\Util\Page(D('UserTempskorder')->where($map)->count(), C('ADMIN_PAGE_ROWS'));
                $ab=D('UserTempskorder')->where($map)->select();
                $user_total=count($ab);

                for($i=0;$i<$user_total;$i++){
                    $money_total=$money_total+$ab[$i]['total_sk'];  //排单总金额
                    $money_ypp=$money_ypp+$ab[$i]['yipipei_money'];   //已匹配金额
                }

                $listName = '等待配对';
                $typenum=1;
                break;
            case 3:
                $map['shoukuan_cishu'] = array('EGT', '1');
                $data_list = D('UserTempskorder')->page(!empty($_GET["p"])?$_GET["p"]:1, C('ADMIN_PAGE_ROWS'))->where($map)->order('sort desc')->select();
                $page = new \Common\Util\Page(D('UserTempskorder')->where($map)->count(), C('ADMIN_PAGE_ROWS'));
                $ab=D('UserTempskorder')->where($map)->select();
                $user_total=count($ab);

                for($i=0;$i<$user_total;$i++){
                    $money_total=$money_total+$ab[$i]['total_sk'];  //排单总金额
                    $money_ypp=$money_ypp+$ab[$i]['yipipei_money'];   //已匹配金额
                }

                $listName = '已配对';
                $typenum=1;
                break;
            case 5:
                $map['shoukuan_cishu'] = array('EGT', '1');
                $data_list = D('UserTempskorder')->page(!empty($_GET["p"])?$_GET["p"]:1, C('ADMIN_PAGE_ROWS'))->where($map)->order('sort desc')->select();
                $page = new \Common\Util\Page(D('UserTempskorder')->where($map)->count(), C('ADMIN_PAGE_ROWS'));
                $ab=D('UserTempskorder')->where($map)->select();
                $user_total=count($ab);

                for($i=0;$i<$user_total;$i++){
                    $money_total=$money_total+$ab[$i]['total_sk'];  //排单总金额
                    $money_ypp=$money_ypp+$ab[$i]['yipipei_money'];   //已匹配金额
                }

                $listName = '交易中';
                $typenum=1;
                break;
            case 6:
                $map['jiaoyi_zt'] = array('eq', '2');
                $data_list = D('UserTempskorder')->page(!empty($_GET["p"])?$_GET["p"]:1, C('ADMIN_PAGE_ROWS'))->where($map)->order('sort desc')->select();
                $page = new \Common\Util\Page(D('UserTempskorder')->where($map)->count(), C('ADMIN_PAGE_ROWS'));
                $ab=D('UserTempskorder')->where($map)->select();
                $user_total=count($ab);

                for($i=0;$i<$user_total;$i++){
                    $money_total=$money_total+$ab[$i]['total_sk'];  //排单总金额
                    $money_ypp=$money_ypp+$ab[$i]['yipipei_money'];   //已匹配金额
                }

                $listName = '交易成功';
                $typenum=1;
                break;
            case 7:
                $map['dk_dakuan_status'] = array('neq', 0);
                $data_list = D('UserPipeioder')->page(!empty($_GET["p"])?$_GET["p"]:1, C('ADMIN_PAGE_ROWS'))->where($map)->order('sort desc')->select();
                $page = new \Common\Util\Page(D('UserPipeioder')->where($map)->count(), C('ADMIN_PAGE_ROWS'));
                $ab=D('UserPipeioder')->where($map)->select();
                $user_total=count($ab);

                for($i=0;$i<$user_total;$i++){
                    $money_total=$money_total+$ab[$i]['dk_money_total'];  //排单总金额
                }

                $listName = '已打款';
                $typenum=2;
                break;
            case 8:
                $map['sf_jy_status'] = array('eq', '8');
                $data_list = D('UserPipeioder')->page(!empty($_GET["p"])?$_GET["p"]:1, C('ADMIN_PAGE_ROWS'))->where($map)->order('sort desc')->select();
                $page = new \Common\Util\Page(D('UserPipeioder')->where($map)->count(), C('ADMIN_PAGE_ROWS'));
                $ab=D('UserPipeioder')->where($map)->select();
                $user_total=count($ab);

                for($i=0;$i<$user_total;$i++){
                    $money_total=$money_total+$ab[$i]['dk_money_total'];  //排单总金额
                }

                $listName = '待抢单';
                $typenum=2;
                break;
            case 9:
                $timetoday = date("Y-m-d",time());
                $time2 = $timetoday + 3600*24;

                $map['sf_dd_crt_time'] = array('between',array('1','8'));
                $data_list = D('UserTempskorder')->page(!empty($_GET["p"])?$_GET["p"]:1, C('ADMIN_PAGE_ROWS'))->where($map)->order('sort desc')->select();
                $page = new \Common\Util\Page(D('UserTempskorder')->where($map)->count(), C('ADMIN_PAGE_ROWS'));
                $ab=D('UserTempskorder')->where($map)->select();
                $user_total=count($ab);

                for($i=0;$i<$user_total;$i++){
                    $money_total=$money_total+$ab[$i]['total_sk'];  //排单总金额
                    $money_ypp=$money_ypp+$ab[$i]['yipipei_money'];   //已匹配金额
                }

                $listName = '交易成功';
                $typenum=1;
                break;
            default:
                $map['jiaoyi_zt'] = array('neq', '19'); //禁用和正常状态
                $data_list = D('UserTempskorder')->page(!empty($_GET["p"])?$_GET["p"]:1, C('ADMIN_PAGE_ROWS'))->where($map)->order('sort desc')->select();
                $page = new \Common\Util\Page(D('UserTempskorder')->where($map)->count(), C('ADMIN_PAGE_ROWS'));
                $ab=D('UserTempskorder')->where($map)->select();
                $user_total=count($ab);

                for($i=0;$i<$user_total;$i++){
                    $money_total=$money_total+$ab[$i]['total_sk'];  //排单总金额
                    $money_ypp=$money_ypp+$ab[$i]['yipipei_money'];   //已匹配金额
                }

                $listName = '全部订单';
                $typenum=1;
                break;
        }


        //获取所有用户
        $builder = new \Common\Builder\ListBuilder();
        $builder->setMetaTitle('收款排队列表'); //设置页面标题
        $this->assign('page',$page->show());
        $this->assign('data_list',$data_list);
        $this->assign('listname',$listName);
        $this->assign('moneytotal',$money_total);
        $this->assign('moneyypp',$money_ypp);
        $this->assign('keykey','ilikemilke');
        $this->assign('total',$user_total);
        $this->assign('typenum',$typenum);
       $this->display();
    }
    public function skListtwo(){
        $dh=$_GET['dh'];
        $type=$_GET['type'];
        if($type==1){  //等于1是原始订单

            $map['sk_lbw_order_pipei'] = $dh;
            $data_list = D('UserPipeioder')->page(!empty($_GET["p"])?$_GET["p"]:1, C('ADMIN_PAGE_ROWS'))->where($map)->order('sort desc')->select();
            $page = new \Common\Util\Page(D('UserPipeioder')->where($map)->count(), C('ADMIN_PAGE_ROWS'));
            $ab=D('UserPipeioder')->where($map)->select();
            $user_total=count($ab);

            for($i=0;$i<$user_total;$i++){
                $money_total=$money_total+$ab[$i]['dk_money_total'];  //排单总金额
            }

            $listName = '匹配详情';

        }else{      //等于2进到双方交易状态


        }
        $builder = new \Common\Builder\ListBuilder();
        $builder->setMetaTitle('提现列表'); //设置页面标题
        $this->assign('page',$page->show());
        $this->assign('data_list',$data_list);
        $this->assign('listname',$listName);
        $this->assign('moneytotal',$money_total);
        $this->assign('keykey','ilikemilke');
        $this->assign('total',$user_total);
        $this->display();
    }
    /*public function piPeizhong(){
        $map['sf_jy_status'] = array('neq', 8);
        $data_list = D('UserPipeioder')->page(!empty($_GET["p"])?$_GET["p"]:1, C('ADMIN_PAGE_ROWS'))->where($map)->select();
        $page = new \Common\Util\Page(D('UserPipeioder')->where($map)->count(), C('ADMIN_PAGE_ROWS'));

        $builder = new \Common\Builder\ListBuilder();
        $builder->setMetaTitle('匹配中列表') //设置页面标题
        ->addTopButton('delete')  //添加删除按钮
        ->addTableColumn('id', 'UID')
            ->addTableColumn('dk_lbw_order_pipei', '单号')
            ->addTableColumn('creattime', '订单创建时间')
            ->addTableColumn('dk_money_total', '双方匹配金额')
            ->addTableColumn('dk_my_mobile', '打款方电话')
            ->addTableColumn('sk_my_mobile', '收款方电话')
            ->addTableColumn('sf_jy_status', '双方交易状态')
            ->addTableColumn('fk_name', '付款姓名')
            ->addTableColumn('sk_name', '收款姓名')
            ->addTableColumn('right_button', '操作', 'btn')
            ->setTableDataList($data_list) //数据列表
            ->setTableDataPage($page->show()) //数据列表分页
            ->addRightButton('delete') //添加删除按钮
            ->display();
    }*/
    //本金利息列表
    public function benJinLx(){
        if (IS_POST) {
            $keyword = I('keyword', '', 'string');
            $condition = array('like', '%' . $keyword . '%');
            $map['dk_sf_jydh|username|lixi_total_day'] = array($condition, $condition, $condition, '_multi' => true);
            $data_list = D('UserLixi')->where($map)->page(!empty($_GET["p"])?$_GET["p"]:1, C('ADMIN_PAGE_ROWS'))->order('lixi_time asc')->select();
            $page = new \Common\Util\Page(D('UserLixi')->where($map)->count(), C('ADMIN_PAGE_ROWS'));
            $builder = new \Common\Builder\ListBuilder();
            $builder->setMetaTitle('本金利息列表');//设置页面标题
            $ab=D('UserLixi')->where($map)->select();
            $user_total=count($ab);

            for($i=0;$i<$user_total;$i++){
                $money_total=$money_total+$ab[$i]['dk_money_total'];  //排单总金额
                $money_ypp=$money_ypp+$ab[$i]['lixi_money'];   //已匹配金额
            }
            $this->assign('moneytotal',$money_total);
            $this->assign('moneyypp',$money_ypp);
            $this->assign('total',$user_total);
            $this->assign('page',$page->show());
            $this->assign('data_list',$data_list);
            $this->display();
        }else{
        $data_list = D('UserLixi')->page(!empty($_GET["p"])?$_GET["p"]:1, C('ADMIN_PAGE_ROWS'))->select();
        $page = new \Common\Util\Page(D('UserLixi')->where($map)->count(), C('ADMIN_PAGE_ROWS'));
        $builder = new \Common\Builder\ListBuilder();
        $builder->setMetaTitle('本金利息列表');//设置页面标题
            $ab=D('UserLixi')->where($map)->select();
            $user_total=count($ab);

            for($i=0;$i<$user_total;$i++){
                $money_total=$money_total+$ab[$i]['dk_money_total'];  //排单总金额
                $money_ypp=$money_ypp+$ab[$i]['lixi_money'];   //已匹配金额
            }
        $this->assign('moneytotal',$money_total);
        $this->assign('moneyypp',$money_ypp);
        $this->assign('total',$user_total);
        $this->assign('page',$page->show());
        $this->assign('data_list',$data_list);
        $this->display();
        }

    }
    public function qiangdan(){
        $map['sf_jy_status'] = array('eq', 8);
        $data_list = D('UserPipeioder')->page(!empty($_GET["p"])?$_GET["p"]:1, C('ADMIN_PAGE_ROWS'))->select();
        $page = new \Common\Util\Page(D('UserPipeioder')->where($map)->count(), C('ADMIN_PAGE_ROWS'));

        $builder = new \Common\Builder\ListBuilder();
        $builder->setMetaTitle('匹配中列表') //设置页面标题
        ->addTopButton('delete')  //添加删除按钮
        ->addTableColumn('id', 'UID')
            ->addTableColumn('dk_lbw_order_pipei', '待抢单号')
            ->addTableColumn('sf_dd_crt_time', '订单创建时间')
            ->addTableColumn('dk_money_total', '交易金额')
            ->addTableColumn('right_button', '操作', 'btn')
            ->setTableDataList($data_list) //数据列表
            ->setTableDataPage($page->show()) //数据列表分页
            ->addRightButton('delete') //添加删除按钮
            ->display();
    }
    //手工充值页面
    public function chouZhi(){
        $this->display();
    }
    //手工充值处理
    public function shouGcz(){
        $dateIF=I('post.lbw_bankname');
        if($dateIF==2){
            $date['username']=I('post.username');
            $qianbao=D('User')->where($date)->getField('user_jt_money');
            $money=I('post.money');
            $data['username']=I('post.username');
            $data['user_jt_money']=$qianbao-$money;
            D('User')->where($date)->save($data);
            $this->success('扣除成功');
        }else{
            $date['username']=I('post.username');
            $qianbao=D('User')->where($date)->getField('user_jt_money');
            $money=I('post.money');
            //以上拿到原始金额
            $data['username']=I('post.username');
            $data['user_jt_money']=$qianbao+$money;
            D('User')->where($date)->save($data); //入库
            $this->success('充值成功');
        }

    }
//清空数据
    public function qksj(){
        $builder = new \Common\Builder\ListBuilder();
        $builder->setMetaTitle('清空数据'); //设置页面标题
        $this->display();
    }
    //清空数据提交
    public function qksjtwo(){
        //清空用户名
        $User = M("User");
        $data['id']=array('NEQ',1);
        $User->where($data)->delete();

        //清空激活码
        $Jhuom=M("Jihuoma");
        $Jhuom->where('1')->delete();

        //清空利息表
        $lixi=M("UserLixi");
        $lixi->where('1')->delete();

        //清空匹配表
        $pipei=M("UserTemppipeiorder");
        $pipei->where('1')->delete();

        //清空收款表
        $sklb=M("UserTempskorder");
        $sklb->where('1')->delete();

        //清空交易表
        $jiaoyi=M("UserPipeioder");
        $jiaoyi->where('1')->delete();

        //清空推广表
        $tuilixi=M("UserTuilixi");
        $tuilixi->where('1')->delete();

        //清空反馈表
        $fankui= M("Fankui");
        $fankui->where('1')->delete();

        //公告列表清空
         $gonggao= M("DocumentArticle");
        $gonggao->where('1')->delete();

        $this->success('数据清除成功', U('Admin/index'));
    }


}
